


//商品界面的获取
$.ajax({
	url:"./php/xiang1.php",
	success:function(dt){
		dt.forEach(function(val){
			$('.nrri').append(`
			<ul>
                <li><a href="./chan1.html"><img src="${val.tupian}"/></a></li>
                <li class="chan_s"><span></span><span></span><span></span><span></span></li>
                <li>${val.biaoti}</li>
                <li>${val.wenben}</li>
                <li>￥<span>${val.jaige}</span></li>
                <li><button>立即购买</button></li>
            </ul>
			`)
			
		})
	},
	dataType: "json",
})


//判断cook是否登录
function ck(key){
    var ckl=document.cookie
    var arr=ckl.split('; ')
    for(var i=0;i<arr.length;i++){
        var zhong1=arr[i].split('=')
        if(zhong1[0]==key){
             var deng1=document.getElementById('deng1')
             deng1.innerHTML="欢迎"+zhong1[1]
        }
    }
}
ck('name')
function lun1(){
	var som=0
	dsq1=setInterval(()=>{
	som++
	if(som>4){
		$('.toulun').css('top',-35)
		som=2
	}
	$('.toulun').animate({top:-som*35},500)
},2000)
}
lun1()

var dao1=document.querySelector('.daobox')
window.onscroll=function(){
	let gun1=window.pageYOffset
	
	if(gun1>100){
		dao1.style.position='fixed'
		dao1.style.borderBottom='3px solid #000'
		dao1.style.zIndex='5'
	}else{
		dao1.style.position=''
		dao1.style.border=''
		dao1.style.zIndex=''
	}
}
//鼠标移入事件
var boy1=document.body
var $xian1=$('.shou12_yi>:nth-child(2)')
var yi1=document.querySelector('.shou12>:nth-child(1)')
var yi2=document.querySelector('.shou12>:nth-child(2)')
yi1.onmousemove=function(){
	$('.shou12_yi>:nth-child(1)').css({display:'block',zIndex:8})
}
yi1.onmouseout=function(){
	$('.shou12_yi>:nth-child(1)').css({display:'none'})
}

// 移入2
yi2.onmousemove=function(){
	$('.shou12_yi>:nth-child(2)').css({display:'block'})
}
yi2.onmouseout=function(){

		$('.shou12_yi>:nth-child(2)').css({display:'none'})

}
var yi22=document.querySelector('.shou12_yi>:nth-child(2)')
yi22.onmouseenter=function(){
	yi22.style.display='block'
}
yi22.onmouseleave=function(){
	yi22.style.display='none'
}


// var div=document.body
// div.onclick=function(e){
// 	var e=e || window.event
// 	var dian=e.target || e.srcElement
// 	for(let i=0;i<)
// }
$('body').on('click','button',function(){
	console.log(111)
	var cc=this.parentNode.parentNode.children[0].innerHTML
	var ming=this.parentNode.parentNode.children[3].innerHTML
	var danjia=this.parentNode.parentNode.children[4].lastElementChild.innerHTML
	$.ajax({
		url:'./php/xiang.php',
		data:{
			"dizhi":cc,
			"mingzi":ming,
			"qian":danjia,
		},
		success:function(dt){
			console.log(dt)
			if(dt==1){
				alert("商品添加成功")
				var a=confirm("是否前往购物车")
				if(a==true){
					window.location.href="./che.html"
				}
			}else{
				alert("商品添加失败")
			}
		}
	})
})